package lc_2874_有序三元组中的最大值_II;

public class Solution {

    public long maximumTripletValue(int[] nums) {
        long ans = 0;
        long diff = nums[0] - nums[1];
        long mx = nums[0];
        for (int i = 2; i < nums.length; i++) {
            diff = Math.max(diff, mx - nums[i - 1]);
            ans = Math.max(ans, diff * nums[i]);
            mx = Math.max(mx, nums[i - 1]);
        }
        return ans;
    }
}